home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBChoose.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  2.9 KB  |  121 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBChoose type -- Allow the user to configure the tool. The type parameter specifies the
  3.         type of tool to configure ("connection", "terminal", or "file transfer").
  4.  
  5.     To compile and link this file using Macintosh Programmer's Workshop,
  6.  
  7.         pascal -w CTBChoose.p
  8.         link -m ENTRYPOINT -o HyperCommands -rt XCMD=2751 -sn Main=CTBChoose ∂
  9.             CTBChoose.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  10.  
  11.     © Copyright 1990 by Apple Computer, Inc.
  12.  
  13.     Initial coding 2/90 by Harry R. Chesley.
  14. *)
  15.  
  16. {$R-}
  17.  
  18. {$S CTBChoose }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. procedure CTBChoose(paramPtr: XCmdPtr); forward;
  31.  
  32. procedure EntryPoint(paramPtr: XCmdPtr);
  33.  
  34.     begin
  35.         CTBChoose(paramPtr);
  36.     end;
  37.  
  38. procedure CTBChoose(paramPtr: XCmdPtr);
  39.  
  40.     {$I CTBUtil.inc}
  41.  
  42.     var i: integer;
  43.         tt: ToolType;
  44.         where: Point;
  45.         result: integer;
  46.         s: Str255;
  47.         oldHand, newHand: ConnHandle;
  48.         cHand: ConnHandle;
  49.         tHand: TermHandle;
  50.         ftHand: FTHandle;
  51.  
  52.     procedure Fail(errMsg: Str255); { set theResult and quit }
  53.         begin
  54.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  55.             exit(CTBChoose);
  56.         end;
  57.  
  58.     begin
  59.         { Verify the parameter count. }
  60.         if (paramPtr^.paramCount > 1) then Fail('Invalid parameter count');
  61.  
  62.         { Get the tool type. }
  63.         if not ParmPresent(1) then tt := connectionTool
  64.         else tt := GetToolTypeParm(1);
  65.  
  66.         { Make sure the Comm Toolbox is ready and willing. }
  67.         CTBReady;
  68.         { And the tool's been allocated. }
  69.         EnsurePresent(tt);
  70.  
  71.         { Prepare to dialog. }
  72.         SetPt(where,10,40);
  73.  
  74.         { Put up a choose dialog for the appropriate tool. }
  75.         case tt of
  76.             connectionTool:
  77.                 begin
  78.                     cHand := Globals^^.connHand;
  79.                     oldHand := cHand;
  80.                     result := CMChoose(cHand,where,nil);
  81.                     Globals^^.connHand := cHand;
  82.                     newHand := cHand;
  83.                 end;
  84.             terminalTool:
  85.                 begin
  86.                     tHand := Globals^^.termHand;
  87.                     oldHand := ConnHandle(tHand);
  88.                     result := TMChoose(tHand,where,nil);
  89.                     Globals^^.termHand := tHand;
  90.                     newHand := ConnHandle(tHand);
  91.                 end;
  92.             fileTransferTool:
  93.                 begin
  94.                     ftHand := Globals^^.FTHand;
  95.                     oldHand := ConnHandle(ftHand);
  96.                     result := FTChoose(ftHand,where,nil);
  97.                     Globals^^.FTHand := ftHand;
  98.                     newHand := ConnHandle(ftHand);
  99.                 end;
  100.             end;
  101.  
  102.         { If we've changed handles, update the outstanding tool list. }
  103.         if newHand <> oldHand then
  104.             for i := 1 to Globals^^.allToolsSize do
  105.                 if Globals^^.allTools[i].cHand = oldHand then Globals^^.allTools[i].cHand := newHand;
  106.  
  107.         { If we ran into problems with the choose, report it. }
  108.         if (result <> chooseOKMinor) and (result <> chooseOKMajor) then
  109.             begin
  110.                 case result of
  111.                     chooseDisaster: s := 'Choose disaster';
  112.                     chooseFailed: s := 'Choose failed';
  113.                     chooseAborted: s := 'Choose aborted';
  114.                     chooseCancel: s := 'Choose cancel';
  115.                     end;
  116.                 Fail(s);
  117.             end;
  118.     end;
  119.  
  120. end.
  121.